package com.ruoyi.request.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.request.domain.TbMatchmakingRequest;
import com.ruoyi.request.service.ITbMatchmakingRequestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.user.domain.TbUser;
import com.ruoyi.matchmaker.domain.TbMatchmaker;
import com.ruoyi.user.mapper.TbUserMapper;

/**
 * 牵线申请Controller
 * 
 * @author ruoyi
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/request/request")
public class TbMatchmakingRequestController extends BaseController
{
    @Autowired
    private ITbMatchmakingRequestService tbMatchmakingRequestService;

    @Autowired
    private TbUserMapper tbUserMapper;

    /**
     * 查询牵线申请列表
     */
    @PreAuthorize("@ss.hasPermi('request:request:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbMatchmakingRequest tbMatchmakingRequest)
    {
        startPage();
        List<TbMatchmakingRequest> list = tbMatchmakingRequestService.selectTbMatchmakingRequestList(tbMatchmakingRequest);
        return getDataTable(list);
    }

    /**
     * 导出牵线申请列表
     */
    @PreAuthorize("@ss.hasPermi('request:request:export')")
    @Log(title = "牵线申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbMatchmakingRequest tbMatchmakingRequest)
    {
        List<TbMatchmakingRequest> list = tbMatchmakingRequestService.selectTbMatchmakingRequestList(tbMatchmakingRequest);
        ExcelUtil<TbMatchmakingRequest> util = new ExcelUtil<TbMatchmakingRequest>(TbMatchmakingRequest.class);
        util.exportExcel(response, list, "牵线申请数据");
    }

    /**
     * 获取牵线申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('request:request:query')")
    @GetMapping(value = "/{requestId}")
    public AjaxResult getInfo(@PathVariable("requestId") Long requestId)
    {
        return success(tbMatchmakingRequestService.selectTbMatchmakingRequestByRequestId(requestId));
    }

    /**
     * 新增牵线申请
     */
    @PreAuthorize("@ss.hasPermi('request:request:add')")
    @Log(title = "牵线申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMatchmakingRequest tbMatchmakingRequest)
    {
        return toAjax(tbMatchmakingRequestService.insertTbMatchmakingRequest(tbMatchmakingRequest));
    }

    /**
     * 修改牵线申请
     */
    @PreAuthorize("@ss.hasPermi('request:request:edit')")
    @Log(title = "牵线申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMatchmakingRequest tbMatchmakingRequest)
    {
        return toAjax(tbMatchmakingRequestService.updateTbMatchmakingRequest(tbMatchmakingRequest));
    }

    /**
     * 删除牵线申请
     */
    @PreAuthorize("@ss.hasPermi('request:request:remove')")
    @Log(title = "牵线申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requestIds}")
    public AjaxResult remove(@PathVariable Long[] requestIds)
    {
        return toAjax(tbMatchmakingRequestService.deleteTbMatchmakingRequestByRequestIds(requestIds));
    }

    /**
     * 根据用户ID获取用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('request:request:query')")
    @GetMapping("/user/{userId}")
    public AjaxResult getUserInfo(@PathVariable("userId") Long userId)
    {
        TbUser user = tbUserMapper.selectTbUserByUserId(userId);
        return success(user);
    }

    /**
     * 根据红娘ID获取红娘详细信息
     */
    @PreAuthorize("@ss.hasPermi('request:request:query')")
    @GetMapping("/matchmaker/{matchmakerId}")
    public AjaxResult getMatchmakerInfo(@PathVariable("matchmakerId") Long matchmakerId)
    {
        TbMatchmaker matchmaker = tbUserMapper.selectTbMatchmakerByMatchmakerId(matchmakerId);
        return success(matchmaker);
    }
}
